CASSGO-4 Support of sending queries to the specific node #1793
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR provides a mechanism that allows users to specify on which node the query will be executed. It is now a typical use case, but it makes sense with virtual tables.
For example, when we want to retrieve metrics for a specific node, we have to send queries to the associated system view of this node.
Implementation Overview
A new method
SetHost()
for theQuery
allows users to specify the host (node) on which we have to send the query. It is implemented by adding a new private interface:When the
queryExecutor.executeQuery
is called then it checks if the providedExecutableQuery
implements thehostGetter
interface as well. We need this interface to not change the APIExecutableQuery
. Also, theExecutableQuery
is implemented byQuery
andBatch
as well, so it is good to avoid adding redundant methods forBatch
as well.So, if provided
ExecutableQuery
implementshostGetter
, then it type-asserts it and calls the underlying method to get the host. If the host is not nil, it wraps the host intohostIter
func which just returns the specified host.This PR also exposes to users
session.GetHosts()
method which calls the underlyingsession.hostSource.GetHosts()
method.Usage Example
Here is an example of retrieving metrics from system_view.cql_metrics for each node of the cluster: